<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%
	//查询门诊收入
	String ksdm = input.getDesc("ksdm","-1"); //传入科室代码代表该科室主任
	String yydm =  input.getDesc("yydm","02");//医院代码
	String date = input.getDesc("start_date","2017-12-18");//开始时间
	String endDa = input.getDesc("end_date","2017-12-24");//结束时间

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
	String nowDate = sdf2.format(sdf.parse(date));
	String nowEndDa = sdf2.format(sdf.parse(endDa));
	
	String startDate = nowDate+"00:00:00";
	String endDate = nowEndDa+"23:59:59";

	String sqlWhere = " and js.sfrq > '"+ startDate + "' and js.sfrq < '" + endDate+"' " ;
	if(!yydm.equals("-1"))
	sqlWhere += " and js.ksdm in (select new map (id as id) from his_dept where yydm ='"+yydm+"') " ;
	if(!"-1".equals(ksdm)){
		sqlWhere += " and js.ksdm in( " + ksdm +")";
	}
	//门诊收入

	//List<Map> feelist = QBuilder.db("basedb").queryHql("select new map( sum(js.zje) as zje  ) from  SF_BRJSK js where js.ybjszt=2 and js.jlzt = 0 " + sqlWhere+ " ");

	List<Map> feelist = QBuilder.db("basedb").queryHql("select new map(sum(convert(numeric(20,4),case when  d.ypbz in (1,2,3) then (case when 0=1 then b.ylsj else b.ylsj-b.yhdj end)*b.ypsl*b.ts*b.cfts/b.ykxs else 0 end)) ypje " +
",sum(convert(numeric(20,4),case when  d.ypbz not in (1,2,3) then (case when 0=1 then b.ylsj else (b.ylsj-b.yhdj) end)*b.ypsl*b.ts*b.cfts/b.ykxs else 0 end)) mzylsr )   " +
"from SF_MZCFK a (nolock)  " +
"inner join  SF_CFMXK b (nolock) on b.cfxh = a.xh   " +
"inner join  YY_YBFLK c (nolock) on a.ybdm = c.ybdm " +
"inner join YY_SFDXMK d (nolock) on d.id = b.dxmdm   " +
"where a.lrrq between  "+startDate+" and "+endDate+" and a.jsbz = 1   " +
" and a.jlzt in (0,1,2,3,4)");
		out.println(feelist);

%>